<template>
    <div>
        <el-form :model='entity' :rules='rules' ref='form'  label-width='80px' class='dialog-form'>

            <el-row :span='24'>
                <el-col :span='12'>
                    <el-form-item style='width:100%' label='类型' prop='type'>
                        <!--<el-input  placeholder='类型' v-model='entity.type'>  </el-input>-->
                        <el-radio v-model="entity.type" :label="10">节假日</el-radio>
                        <el-radio v-model="entity.type" :label="20">工作日</el-radio>

                    </el-form-item>
                </el-col>
                <el-col :span='12'>
                    <el-form-item style='width:100%' label='标识' prop='id'>
                        <el-input  disabled placeholder='标识' v-model='entity.id'>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span='12'>
                    <el-form-item style='width:100%' label='日期' prop='day'><el-date-picker style='width:100%'v-model='entity.day' format='yyyy 年 MM 月 dd 日' value-format='yyyy-MM-dd HH:mm:ss'  type='date' placeholder='选择日期'>  </el-date-picker>
                    </el-form-item>
                </el-col>

                <el-col :span='12'>
                    <el-form-item style='width:100%' label='节日名称' prop='name'>
                        <el-input  :disabled="entity.type==20" placeholder='节日名称' v-model='entity.name'>
                        </el-input>
                    </el-form-item>
                </el-col>

                <!--<el-col :span='12'>-->
                    <!--<el-form-item style='width:100%' label='创建日期' prop='createdAt'>-->
                        <!--<el-input disabled placeholder='创建日期' v-model='entity.createdAt'>-->
                        <!--</el-input>-->
                    <!--</el-form-item>-->
                <!--</el-col>-->
                <el-col :span='12'>
                    <el-form-item style='width:100%' label='创建人' prop='createdBy'>
                        <el-input  disabled placeholder='创建人' v-model='entity.username'>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>
<style lang="less" scoped>
    .productLogo .el-upload-dragger {
        img {
            width: 200px;
            height: 100px !important;
        }
    }

    .clsCommon {
        margin-top: 10px;
        margin-left: -15px;
        margin-right: 15px;
    }

    .dialog-form {
        .el-radio-group {
            .el-radio {
                display: flex;
                align-items: center;
            }

            label {
                height: 40px;
            }
            .group-text {
                display: inline-block;
                width: 100px;
            }
            .title-text {
                display: inline-block;
                width: 120px;
            }
        }

    }
</style>

<script>

   // import ProductTypeSelect from '@/components/widgets/dongxw/ProductTypeSelect.vue';


    const defaultEntity = {
        id:  null,	//  标识
        day:  null,	//  日期
        type:  10,	//  类型
        name: ' ',
        createdAt:  '2020-01-01 00:00:00' ,	//  创建日期
        createdBy:  0,	//  创建人
    };

    export default {
        components: {  },
        data() {
            return {

                isShow: true,
                multiple: true,
                isExp: false,
                activeName: 'productInfo',

                ruleTpl: {when: null, then: null},
                entity: _.cloneDeep(defaultEntity),
                dateRange: [],
                oldProps: [],
                ruleDefs: [],
                isDisabled: false,
                limitTotal: false,
                rules: {

                    day: [
                        {
                            required: true,
                        }
                    ],

                }
            };
        },
        computed: {
            cbm: {
                get() {
                    let v = this.entity.obSize.split('*')

                    if (v.length === 3) {
                        var multi = function (a, b) {
                            return parseInt(a) * parseInt(b);
                        }
                        return (v.reduce(multi, 1) / 1000000).toFixed(4)
                    }
                    return 0;
                }
            }
        },
        methods: {

            clearImg() {
                this.entity.picUrl = null;
            },


            funHandleChange(imgRemarkArray) {
             },

            getProps(scope) {
                return this.entity.props.filter(p => p.propScope == scope);
            },
            onRuleDefsLoaded(opts) {
                this.ruleDefs = opts || [];
                this.resetProps();
            },

            resetProps() {


            },
            setValues(vals) {
                this.resetEntity = _.cloneDeep(vals);
                this.entity = _.cloneDeep(this.resetEntity);
            },
            submitForm() {

                this.$refs["form"].validate(valid => {
                    if (valid) {

                        let params = Object.assign({}, this.entity);

                        this.$api.attend.attend.DayService.save(params).then(rsp => {
                            this.$emit("saved", rsp);
                        });
                    }
                });
            },
            resetForm() {
                this.entity = _.cloneDeep(defaultEntity);
                if (!this.entity.id) {

                    this.entity.createDate = this.$dongxwDict.formatDateZero(new Date())
                }
            },
            init(options) {
                this.resetForm();
                if (options.id) {
                    this.$api.attend.attend.DayService.findById(options.id).then(r => {

                        this.entity = r.data;

                    });
                } else {
                    this.isDisabled = false;
                }
            }
        },
        mounted() {
            this.$on("init", this.init);
            this.$on("submit", this.submitForm);
        }
    };
</script>
